import unittest
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By

class TestGoogleSearch(unittest.TestCase):

    def setUp(self):
        # 设置正确的驱动路径
        service = ChromeService(executable_path="D:\Downloads\chromedriver-win64\chromedriver-win64\chromedriver.exe")
        options = webdriver.ChromeOptions()
        driver = webdriver.Chrome(service=service, options=options)
        self.driver.get("https://www.baidu.com")

    def test_search(self):
        search_box = self.driver.find_element(By.NAME, "wd")
        search_box.send_keys("Selenium")
        search_box.submit()
        self.assertIn("Selenium", self.driver.title)

    def tearDown(self):
        self.driver.quit()

if __name__ == "__main__":
    unittest.main()